package actionHandlers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

import palette.CanvasManager;
import palette.CanvasWindow;

public class ExportHandler implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {

		try {
			
			JFileChooser chooser = new JFileChooser(new File(System.getProperty("user.dir")));
		    FileNameExtensionFilter filter = new FileNameExtensionFilter(
		        "PNG Image", "PNG");
		    chooser.setFileFilter(filter);
		    if(chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
		    	CanvasWindow temp = (CanvasWindow)(CanvasManager.getInst().getSelectedFrame());
		    	File extFile = new File(chooser.getSelectedFile().getAbsolutePath() + ".PNG");
		    	temp.getCanvas().exportImage(extFile);
		    	System.out.println(chooser.getSelectedFile().getName());
		    }
			
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		
	}

}
